#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: three_nums_sum.py 
@version:
@time: 2023/12/28 
"""
array = [-1, 0, 1, 2, -1, -4]


def three_sum(arr):
    # 排序
    arr.sort()
    # 获取数组长度
    length = len(arr)
    # 初始化结果集
    res = []

    # 硬算
    # 判断i,j,k和为0，且结果之一不在结果集
    for i in range(length):
        for j in range(i + 1, length):
            for k in range(j + 1, length):
                if arr[i] + arr[j] + arr[k] == 0 and \
                        not [arr[i], arr[j], arr[k]] in res:
                    res.append([arr[i], arr[j], arr[k]])
    return res


if __name__ == '__main__':
    print(three_sum(array))
